"""
URL configuration for djangoLearning project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include, reverse
from django.shortcuts import HttpResponse
from book import views as book_views


def index(request):
    # print(reverse("book_detail_query_string") + "?id=1")

    print(reverse("movie:movie_list"))
    return HttpResponse("Hello world")


urlpatterns = [

    path('', index, name='index'),

    path('admin/', admin.site.urls),
    # path('hello', index)

    # http://localhost:8000/book?id=1&name=书名
    path('book', book_views.book_detail_query_string, name='book_detail_query_string'),
    # http://localhost:8000/book/1
    # 在这里指定参数类型又两个好处
    # 1.以后在浏览器中，如果输入的是一个非整形，那么会出现404错误：/book/abc
    # 2.在视图函数中，得到的book_id一定是一个整形
    path('book/<int:book_id>', book_views.book_detail_path),
    # http://localhost:8000/book/str/abcd
    path('book/str/<str:book_id>', book_views.book_str, name='book_str'),
    # http://localhost:8000/book/slug/11-abcd_33
    # 加name属性便于路由反转
    path('book/slug/<slug:book_id>', book_views.book_slug, name="book_slug"),
    # http://localhost:8000/book/path/11/33
    path('book/path/<path:book_id>', book_views.book_path, name="book_path"),

    path('movie/', include('movie.urls'))
]
